/**
 * @project readnote
 * @Title BookDAOImpl.java
 * @author huxh
 * @date 2012-2-12
 **/
package com.readnote.book.dao.impl;

import java.util.List;

import com.cr.backbone.hibenate.AppBaseDAOImpl;
import com.cr.backbone.hibenate.QueryParam;
import com.readnote.book.dao.UserNoteDAO;
import com.readnote.book.model.UserBook;
import com.readnote.book.model.UserNote;
import com.readnote.user.model.User;

public class UserNoteDAOImpl extends AppBaseDAOImpl<UserNote> implements  UserNoteDAO {

//	/**
//	 * 获取单个用户书籍对象,by用户、书籍
//	 * @param book
//	 * @param user
//	 * @return
//	 */
//	public UserNote getUserNoteByBookAndUser(Book book, User user) {
//		String hql="FROM UserNote ub where ub.user.id = ? and ub.book.id = ?";
////		String[] paramNames={"userId","bookId"};
//		Object[] values={user.getId(),book.getId()};
//		return getByHql(hql, values);
//	}
//	
	
	

	/**
	 * 获取用户笔记集合，by用户书籍
	 * @param userBook
	 * @return
	 */
	public List<UserNote> getListUserNoteByUserBook(UserBook userBook){
		String hql="FROM UserNote un where un.userBook.id = :userBookId";
		String[] paramNames={"userBookId"};
		Object[] values={userBook.getId()};
		return getListByHql(hql, paramNames, values);
	}
	
	public List<UserNote> getListUserNoteByUser(User user){
		String hql="FROM UserNote un where un.user.id = :userId";
		String[] paramNames={"userId"};
		Object[] values={user.getId()};
		return getListByHql(hql, paramNames, values);
		
	}
	
	/**
	 * 获取用户最后添加笔记
	 * @param user
	 * @return
	 * @author huxh
	 * @date 2012-7-5 
	 */
	public UserNote getUserNoteTopOneByUser(User user){
		QueryParam param=new QueryParam();
		param.addQuery("eq_user.id_l", user.getId());
		param.addOrderDesc("id");
		return getByCriteria(param);
	}
}
